/**  
 * 上传文件
 */
import axios from 'axios';
import server from './serve';
import {
  Toast
} from 'mint-ui';
export default {
  //   上传一个图片
  post(url,params,callback) {
    let config = {
      headers: { //添加请求头
        Authorization: "Bearer " + window.localStorage.getItem("managementToken"),
        "Content-Type": "multipart/form-data"
      }
    };
    axios.post(server[url], params, config).then(res => {
      if(res.data.recode==1){
        callback(res.data);
      }else{
        Toast({
          message: res.data.msg,
          position: 'middle',
          duration: 2000
        })
      }
    }).catch(err => {
      Toast({
        message: '上传失败',
        position: 'middle',
        duration: 2000
      })
    });
  }
}
